package com.example.administrator.hqq.adapter.dialog;

import android.content.Context;
import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.load.resource.bitmap.CenterCrop;
import com.example.administrator.hqq.R;
import com.example.administrator.hqq.adapter.SetOnClickItem;
import com.example.administrator.hqq.bean.DIalogContactBean;
import com.example.administrator.hqq.utils.transform.GlideCircleTransform;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * @name: HQQ
 * @describe:
 * @author: 康海涛 QQ2541849981
 * @time: 2018/11/30 14:15
 * @remark:
 */
public class ContactItemAdapter extends RecyclerView.Adapter<ContactItemAdapter.ViewHolder> {
    private Context context;
    private List<DIalogContactBean.DataBean.ContactBean>  data;
    private SetOnClickItem setOnClickItem;
    public ContactItemAdapter(Context context, List<DIalogContactBean.DataBean.ContactBean> contact) {
        this.context=context;
        this.data=contact;
    }

    @NonNull
    @Override
    public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View inflate = LayoutInflater.from(context).inflate(R.layout.contact_group_item, null);
        ViewHolder viewHolder = new ViewHolder(inflate);
        return viewHolder;
    }

    @Override
    public void onBindViewHolder(@NonNull ViewHolder holder, final int position) {
        Glide.with(context).load(data.get(position)
                .getUrl())
                .transform(new CenterCrop(context),new GlideCircleTransform(context))
                .into(holder.pic);
        holder.title.setText(data.get(position).getTitle());
        if (!TextUtils.isEmpty(data.get(position).getRemark())){
            holder.remarkText.setVisibility(View.VISIBLE);
            holder.remarkText.setText(data.get(position).getRemark());
        }else{
            holder.remarkText.setVisibility(View.GONE);
        }
        holder.itemview.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (setOnClickItem!=null)
                {
                    setOnClickItem.setOnClickItem(position);
                }
            }
        });
        holder.itemview.setOnLongClickListener(new View.OnLongClickListener() {
            @Override
            public boolean onLongClick(View view) {
                if (setOnClickItem!=null)
                {
                    setOnClickItem.setPicsOnClickItem(position);
                }
                return false;
            }
        });
    }

    @Override
    public int getItemCount() {
        return data.size();
    }

    public void setSetOnClickItem(SetOnClickItem setOnClickItem) {
        this.setOnClickItem = setOnClickItem;
    }

    class ViewHolder extends RecyclerView.ViewHolder {
        @BindView(R.id.pic)
        ImageView pic;
        @BindView(R.id.title)
        TextView title;
        @BindView(R.id.remark_text)
        TextView remarkText;
        View itemview;
        public ViewHolder(View itemView) {
            super(itemView);
            itemview=itemView;
            ButterKnife.bind(this, itemView);
        }
    }
}
